package com.ego.service.impl;

import com.ego.dubbo.service.ContentDubboService;
import com.ego.pojo.BigAdPojo;
import com.ego.pojo.Content;
import com.ego.service.PortalService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PortalServiceImpl implements PortalService {

    @DubboReference
    private ContentDubboService contentDubboService;

    @Value("${ego.bigad.id}")
    private long bigadid;

    @Override
    @Cacheable(cacheNames = "com.ego",key = "'bigad'")
    public List<BigAdPojo> selectByPage() {
        List<BigAdPojo> bigAdPojos = new ArrayList<>();
        List<Content> contents = contentDubboService.selectContentByPage(bigadid, 1, 6);
        for (Content content : contents) {
            BigAdPojo bigAdPojo = new BigAdPojo();
            bigAdPojo.setId(content.getId());
            bigAdPojo.setHref(content.getUrl());
            bigAdPojo.setAlt("");
            bigAdPojo.setSrc(content.getPic());
            bigAdPojo.setWidth(670);
            bigAdPojo.setHeight(240);
            bigAdPojo.setSrcB(content.getPic2());
            bigAdPojo.setWidthB(550);
            bigAdPojo.setHeightB(240);

            bigAdPojos.add(bigAdPojo);
        }

        return bigAdPojos;
    }

}
